package com.panopset.net.ftp;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;

public class FTPDataSocket extends AbstractSocket {
    private BufferedInputStream inputStream;
    private BufferedOutputStream outputStream;

    FTPDataSocket(String host, int port) {
        super(host, port);
    }

    BufferedInputStream getInputStream() throws IOException {
        if (inputStream == null) {
            inputStream = new BufferedInputStream(getSocket().getInputStream());
        }
        return inputStream;
    }

    BufferedOutputStream getOutputStream() throws IOException {
        if (outputStream == null) {
            outputStream = new BufferedOutputStream(getSocket().getOutputStream());
        }
        return outputStream;
    }

    @Override
    public void close() throws IOException {
        if (inputStream != null) inputStream.close();
        if (outputStream != null) {
            outputStream.flush();
            outputStream.close();
        }
        inputStream = null;
        outputStream = null;
    }
}
